import { createRouter, createWebHashHistory } from 'vue-router'

// 布局组件
import Layout from '../views/layout/index.vue'

// 路由配置
const routes = [
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: '/dashboard',
        name: 'Dashboard',
        component: () => import('@/views/dashboard/index.vue'),
        meta: { title: '仪表盘', icon: 'el-icon-s-home' }
      },
      {
        path: '/trading',
        name: 'Trading',
        component: () => import('@/views/trading/index.vue'),
        meta: { title: '模拟交易', icon: 'el-icon-s-finance' }
      },
      {
        path: '/contract',
        name: 'ContractTrading',
        component: () => import('@/views/trading/contract.vue'),
        meta: { title: '合约交易', icon: 'el-icon-s-finance' }
      },
      {
        path: '/arbitrage',
        name: 'Arbitrage',
        component: () => import('@/views/arbitrage/index.vue'),
        meta: { title: '搬砖套利', icon: 'el-icon-s-data' }
      },
      {
        path: '/settings',
        name: 'Settings',
        component: () => import('@/views/settings/index.vue'),
        meta: { title: '系统设置', icon: 'el-icon-setting' }
      }
    ]
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

// 路由守卫
router.beforeEach((to, from, next) => {
  // 设置页面标题
  document.title = to.meta.title || 'Electron Vue Admin'
  next()
})

export default router